package com.vancouver.knows.business.task;

import android.util.Log;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.alibaba.fastjson.JSON;
import com.pangu.bean.PageInfo;
import com.pangu.service.IService;
import com.pangu.task.AServiceWrapper;
import com.pangu.task.AsyncOperation;
import com.pangu.task.IResultReceiver;
import com.pangu.task.mark.ATaskMark;
import com.pangu.util.DeviceUtil;
import com.pangu.util.StringUtil;
import com.vancouver.knows.business.BSharedPrefManager;
import com.vancouver.knows.business.BusinessModule;
import com.vancouver.knows.business.bean.NameValuePair;
import com.vancouver.knows.business.bean.UserInfo;
import com.vancouver.knows.business.bean.VersionInfo;
import com.vancouver.knows.business.cache.CacheManager;
import com.vancouver.knows.business.cache.PersistentCacheManager;
import com.vancouver.knows.business.task.mark.FetchCityNewsTaskMark;
import com.vancouver.knows.business.task.mark.FetchCommentsTaskMark;
import com.vancouver.knows.business.task.mark.FetchUserBusinessImagesTaskMark;
import com.vancouver.knows.business.task.mark.FetchUserPostCategoriesTaskMark;
import com.vancouver.knows.business.task.mark.FetchUserPostsTaskMark;
import com.vancouver.knows.business.task.mark.GetUserPostsTaskMark;
import com.vancouver.knows.business.task.mark.HomeMapTaskMark;
import com.vancouver.knows.business.task.mark.SearchResultTaskMark;
import com.vancouver.knows.business.task.mark.UploadBusinessPhotosTaskMark;
import com.vancouver.knows.business.task.mark.UserGetAuidTaskMark;
import com.vancouver.knows.business.tracker.ABInvokeTracker;
import com.vancouver.knows.business.tracker.AddUserTokenTracker;
import com.vancouver.knows.business.tracker.ChangeUserImagerTracker;
import com.vancouver.knows.business.tracker.EmptyTracker;
import com.vancouver.knows.business.tracker.FetchCityDiscountsCategoryTracker;
import com.vancouver.knows.business.tracker.FetchCityDiscountsTracker;
import com.vancouver.knows.business.tracker.FetchCityNewsDetailTracker;
import com.vancouver.knows.business.tracker.FetchCityNewsTracker;
import com.vancouver.knows.business.tracker.FetchCommentsTracker;
import com.vancouver.knows.business.tracker.FetchDiscountDetailTracker;
import com.vancouver.knows.business.tracker.FetchEventDetailTracker;
import com.vancouver.knows.business.tracker.FetchEventsTracker;
import com.vancouver.knows.business.tracker.FetchHomeMapTracker;
import com.vancouver.knows.business.tracker.FetchUserBusinessImagesTracker;
import com.vancouver.knows.business.tracker.FetchUserPostCategoriesTracker;
import com.vancouver.knows.business.tracker.FetchUserPostDetailTracker;
import com.vancouver.knows.business.tracker.FetchUserPostsTracker;
import com.vancouver.knows.business.tracker.ForgotPasswordTracker;
import com.vancouver.knows.business.tracker.GetUserPostsTracker;
import com.vancouver.knows.business.tracker.HomePageTracker;
import com.vancouver.knows.business.tracker.LiveFeedTracker;
import com.vancouver.knows.business.tracker.ModifyPasswordTracker;
import com.vancouver.knows.business.tracker.MyArticleFollowCommentTracker;
import com.vancouver.knows.business.tracker.MyUserNoticeTracker;
import com.vancouver.knows.business.tracker.PostPrivacySettingTracker;
import com.vancouver.knows.business.tracker.QueryUserInfoTracker;
import com.vancouver.knows.business.tracker.SplashAdInfoTracker;
import com.vancouver.knows.business.tracker.UploadUserPostTracker;
import com.vancouver.knows.business.tracker.UserDelCommentTracker;
import com.vancouver.knows.business.tracker.UserDeleteArticleTracker;
import com.vancouver.knows.business.tracker.UserDeleteFollowTracker;
import com.vancouver.knows.business.tracker.UserDeleteUpvoteTracker;
import com.vancouver.knows.business.tracker.UserEditProfileTracker;
import com.vancouver.knows.business.tracker.UserFollowTracker;
import com.vancouver.knows.business.tracker.UserGetAuidTracker;
import com.vancouver.knows.business.tracker.UserGetNoticationSettingTracker;
import com.vancouver.knows.business.tracker.UserHashTracker;
import com.vancouver.knows.business.tracker.UserInfoTracker;
import com.vancouver.knows.business.tracker.UserInsertCommentTracker;
import com.vancouver.knows.business.tracker.UserRateTracker;
import com.vancouver.knows.business.tracker.UserRegisterTracker;
import com.vancouver.knows.business.tracker.UserSearchTotalTracker;
import com.vancouver.knows.business.tracker.UserSearchTracker;
import com.vancouver.knows.business.tracker.UserUpvoteTracker;
import com.vancouver.knows.business.tracker.VersionInfoTracker;

/**
 * 任务封装
 * <p/>
 * Created by cxlin
 */
public class BServiceWrapper extends AServiceWrapper {

    private BusinessModule modulel;
    private BTaskMarkPool taskMarkPool;
    private BSharedPrefManager sharedPrefManager;

    public BServiceWrapper(BusinessModule modulel, IService service) {
        super(modulel.getAMApplication(), service);
        this.modulel = modulel;
        taskMarkPool = modulel.getTaskMarkPool();
        sharedPrefManager = (BSharedPrefManager)modulel.getAMApplication().getSharedPrefManager();
    }


    private AsyncOperation createAsyncOperation(String method, IResultReceiver resultReceiver, ATaskMark taskMark,
                                                ABInvokeTracker tracker, final Object... args) {
        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);

            } else {
                operation = wraperOperation(tracker, taskMark, method, null);
                operation.excuteOperate(service, args);
            }

            return operation;

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    private AsyncOperation createAsyncOperation(String method, IResultReceiver resultReceiver, ATaskMark taskMark,
                                                ABInvokeTracker tracker, List<NameValuePair> datas) {
        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);

            } else {
                operation = wraperOperation(tracker, taskMark, method, null);
                operation.excuteOperate(service, datas);
            }

            return operation;

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 查询城事列表
     *
     * @param resultReceiver 结果接收器
     * @param order          排序
     * @param category       类型
     * @param userId         用户id
     * @return
     */
    public AsyncOperation fetchCityNews(IResultReceiver resultReceiver, String order, String category, String userId) {
        FetchCityNewsTracker tracker = new FetchCityNewsTracker(modulel, resultReceiver);
        FetchCityNewsTaskMark taskMark = taskMarkPool.getFetchCityNewsTaskMarkList(order, category);
        PageInfo pageInfo = taskMark.getPageInfo();
        List<NameValuePair> datas = new ArrayList<>();
        datas.add(new NameValuePair("page", "citynews")); //citynews_home
        datas.add(new NameValuePair("from", pageInfo.getNextFrom() + ""));
        datas.add(new NameValuePair("size", pageInfo.getSize() + ""));
        if (!StringUtil.isEmptyString(order)) {
            datas.add(new NameValuePair("order", order));
        }
        if (!StringUtil.isEmptyString(category)) {
            datas.add(new NameValuePair("category", category));
        }
        if (!StringUtil.isEmptyString(userId)) {
            datas.add(new NameValuePair("user_id", userId));
        } else {
            datas.add(new NameValuePair("auid", sharedPrefManager.getAuid()));
        }

        return createAsyncOperation("fetchCityNews", resultReceiver, taskMark, tracker, datas);
    }

    /**
     * 登录
     *
     * @param resultReceiver 结果接收器
     * @param taskMark       任务标记
     * @param email          邮箱
     * @param phone          手机号
     * @param password       密码
     * @param gcmToken       token
     * @return
     */
    public AsyncOperation login(IResultReceiver resultReceiver, ATaskMark taskMark, String email, String phone,
                                String password, String gcmToken) {
        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);

            } else {
                UserInfoTracker tracker = new UserInfoTracker(modulel, resultReceiver);
                operation = wraperOperation(tracker, taskMark, "userLogin", null);
                operation.excuteOperate(service, email, phone, password, gcmToken);
            }

            return operation;

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 查询用户信息
     *
     * @param resultReceiver 用户接收器
     * @param taskMark       任务标记
     * @param userID         用户id
     * @return
     */
    public AsyncOperation queryUserInfo(IResultReceiver resultReceiver, ATaskMark taskMark, String userID) {
        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);
                return operation;
            }
            QueryUserInfoTracker tracker = new QueryUserInfoTracker(modulel, resultReceiver);
            operation = wraperOperation(tracker, taskMark, "queryUserInfo", null);
            operation.excuteOperate(service, userID);
        } catch (Exception e) {
        }

        return null;
    }

    /**
     * 点赞
     *
     * @param resultReceiver 用户接收器
     * @param taskMark       任务标记
     * @param userId         用户id
     * @param targetId       记录id
     * @param targetType     记录类型
     * @return
     */
    public AsyncOperation userUpvote(IResultReceiver resultReceiver, ATaskMark taskMark, String userId,
                                     String auid, String targetId, String targetType) {
        UserUpvoteTracker tracker = new UserUpvoteTracker(modulel, resultReceiver);
        List<NameValuePair> datas = new ArrayList<>();
        datas.add(new NameValuePair("page", "user_upvote"));
        if (!StringUtil.isEmptyString(auid)) {
            datas.add(new NameValuePair("auid", auid));
        } else if(!StringUtil.isEmptyString(userId)) {
            datas.add(new NameValuePair("user_id", userId));
        }
        datas.add(new NameValuePair("target_id", targetId));
        datas.add(new NameValuePair("target_type", targetType));

        return createAsyncOperation("userUpvote", resultReceiver, taskMark, tracker, datas);
    }

    /**
     * 删除用户点赞
     *
     * @param resultReceiver 结果接收器
     * @param taskMark       任务标记
     * @param userId         用户id
     * @param targetId       记录id
     * @param targetType     记录类型
     * @return
     */
    public AsyncOperation userDeleteUpvote(IResultReceiver resultReceiver, ATaskMark taskMark, String userId,
                                           String auid, String targetId, String targetType) {
        UserDeleteUpvoteTracker tracker = new UserDeleteUpvoteTracker(modulel, resultReceiver);
        List<NameValuePair> datas = new ArrayList<>();
        datas.add(new NameValuePair("page", "user_delete_vote"));
        if (!StringUtil.isEmptyString(auid)) {
            datas.add(new NameValuePair("auid", auid));
        } else if(!StringUtil.isEmptyString(userId)) {
            datas.add(new NameValuePair("user_id", userId));
        }
        datas.add(new NameValuePair("target_id", targetId));
        datas.add(new NameValuePair("target_type", targetType));

        return createAsyncOperation("userDeleteUpvote", resultReceiver, taskMark, tracker, datas);
    }

    /**
     * 查询活动列表
     *
     * @param resultReceiver 结果接收器
     * @param taskMark       任务标记
     * @param userId         用户id
     * @param fdg            起始时间
     * @return
     */
    public AsyncOperation fetchEvents(IResultReceiver resultReceiver, ATaskMark taskMark, String userId, String fdg) {
        FetchEventsTracker tracker = new FetchEventsTracker(modulel, resultReceiver);
        List<NameValuePair> datas = new ArrayList<>();
        datas.add(new NameValuePair("page", "event_home"));
        if (!StringUtil.isEmptyString(userId)) {
            datas.add(new NameValuePair("user_id", userId));
        }
        datas.add(new NameValuePair("from_date_gmt", fdg));

        return createAsyncOperation("fetchEvents", resultReceiver, taskMark, tracker, datas);
    }

    /**
     * 用户忘记密码接口
     *
     * @param resultReceiver 结果接收器
     * @param taskMark       任务标记
     * @param email          邮箱
     * @param phone          手机号码
     * @return
     */
    public AsyncOperation forgotPassword(IResultReceiver resultReceiver, ATaskMark taskMark, String phone, String
            email) {
        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);

            } else {
                ForgotPasswordTracker tracker = new ForgotPasswordTracker(modulel, resultReceiver);
                operation = wraperOperation(tracker, taskMark, "forgotPassword", null);
                operation.excuteOperate(service, phone, email);
            }

            return operation;

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 修改密码
     *
     * @param resultReceiver
     * @param taskMark
     * @param phone
     * @param email
     * @param verificationCode
     * @param userPassword
     * @return
     */
    public AsyncOperation modifyPassword(IResultReceiver resultReceiver, ATaskMark taskMark, String phone,
                                         String email, String verificationCode, String userPassword) {
        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);

            } else {
                ModifyPasswordTracker tracker = new ModifyPasswordTracker(modulel, resultReceiver);
                operation = wraperOperation(tracker, taskMark, "modifyPassword", null);
                operation.excuteOperate(service, phone, email, verificationCode, userPassword);
            }

            return operation;

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 查询活动详情
     *
     * @param resultReceiver 结果接收器
     * @param taskMark       任务标记
     * @param postId         活动id
     * @param userId         用户id
     * @return
     */
    public AsyncOperation fetchEventDetail(IResultReceiver resultReceiver, ATaskMark taskMark, String postId,
                                           String userId) {
        FetchEventDetailTracker tracker = new FetchEventDetailTracker(modulel, resultReceiver);
        List<NameValuePair> datas = new ArrayList<>();
        datas.add(new NameValuePair("page", "event_single"));
        datas.add(new NameValuePair("post_id", postId));
        if (!StringUtil.isEmptyString(userId)) {
            datas.add(new NameValuePair("user_id", userId));
        }

        return createAsyncOperation("fetchEventDetail", resultReceiver, taskMark, tracker, datas);
    }

    /**
     * 关注
     *
     * @param resultReceiver 结果接收器
     * @param taskMark       任务标记
     * @param postId         文章id
     * @param userId         用户id
     * @return
     */
    public AsyncOperation userFollow(IResultReceiver resultReceiver, ATaskMark taskMark, String postId, String
            userId) {
        UserFollowTracker tracker = new UserFollowTracker(modulel, resultReceiver);
        List<NameValuePair> datas = new ArrayList<>();
        datas.add(new NameValuePair("page", "user_follow"));
        datas.add(new NameValuePair("post_id", postId));
        datas.add(new NameValuePair("user_id", userId));

        return createAsyncOperation("userFollow", resultReceiver, taskMark, tracker, datas);
    }

    /**
     * 删除用户关注
     *
     * @param resultReceiver 结果接收器
     * @param taskMark       任务标记
     * @param postId         文章id
     * @param userId         用户id
     * @return
     */
    public AsyncOperation userDeleteFollow(IResultReceiver resultReceiver, ATaskMark taskMark, String postId,
                                           String userId) {
        UserDeleteFollowTracker tracker = new UserDeleteFollowTracker(modulel, resultReceiver);
        List<NameValuePair> datas = new ArrayList<>();
        datas.add(new NameValuePair("page", "user_delete_follow"));
        datas.add(new NameValuePair("post_id", postId));
        datas.add(new NameValuePair("user_id", userId));

        return createAsyncOperation("userDeleteFollow", resultReceiver, taskMark, tracker, datas);
    }

    /**
     * email 发送验证码
     *
     * @param resultReceiver
     * @param taskMark
     * @param email
     * @return
     */
    public AsyncOperation userEmailSendSecurityCode(IResultReceiver resultReceiver, ATaskMark taskMark, String email) {
        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);
            } else {
                EmptyTracker tracker = new EmptyTracker(modulel, resultReceiver);
                operation = wraperOperation(tracker, taskMark, "emailSendSecurityCode", null);
                operation.excuteOperate(service, email);
            }

            return operation;

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * email 用户注册
     *
     * @param resultReceiver
     * @param taskMark
     * @param email
     * @param verificationCode
     * @param userNickname
     * @param password
     * @return
     */
    public AsyncOperation userEmailRegister(IResultReceiver resultReceiver, ATaskMark taskMark, String email,
                                            String verificationCode, String userNickname, String password) {
        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);
            } else {
                UserRegisterTracker tracker = new UserRegisterTracker(modulel, resultReceiver);
                operation = wraperOperation(tracker, taskMark, "emailUserRegister", null);
                operation.excuteOperate(service, email, verificationCode, userNickname, password);
            }

            return operation;

        } catch (Exception e) {
        }

        return null;
    }

    /**
     * 手机注册 发送验证码
     *
     * @param resultReceiver
     * @param taskMark
     * @param phone
     * @return
     */
    public AsyncOperation userPhoneSendSecurityCode(IResultReceiver resultReceiver, ATaskMark taskMark, String phone) {
        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);
            } else {
                EmptyTracker tracker = new EmptyTracker(modulel, resultReceiver);
                operation = wraperOperation(tracker, taskMark, "phoneSendSecurityCode", null);
                operation.excuteOperate(service, phone);
            }

            return operation;
        } catch (Exception e) {
        }

        return null;
    }

    /**
     * 手机 用户注册
     *
     * @param resultReceiver
     * @param taskMark
     * @param phone
     * @param verificationCode
     * @param userNickname
     * @param password
     * @return
     */
    public AsyncOperation userPhoneRegister(IResultReceiver resultReceiver, ATaskMark taskMark, String phone,
                                            String verificationCode, String userNickname, String password) {
        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);

            } else {
                UserRegisterTracker tracker = new UserRegisterTracker(modulel, resultReceiver);
                operation = wraperOperation(tracker, taskMark, "phoneUserRegister", null);
                operation.excuteOperate(service, phone, verificationCode, userNickname, password);
            }

            return operation;
        } catch (Exception e) {
        }

        return null;
    }

    /**
     * 查询城事详情
     *
     * @param resultReceiver 结果接收器
     * @param taskMark       任务标记
     * @param postId         文章id
     * @param userId         用户id
     * @return
     */
    public AsyncOperation fetchCityNewsDetail(IResultReceiver resultReceiver, ATaskMark taskMark, String postId,
                                              String userId) {
        FetchCityNewsDetailTracker tracker = new FetchCityNewsDetailTracker(modulel, resultReceiver);
        List<NameValuePair> datas = new ArrayList<>();
        datas.add(new NameValuePair("page", "post_single"));
        datas.add(new NameValuePair("post_id", postId));
        if (!StringUtil.isEmptyString(userId)) {
            datas.add(new NameValuePair("user_id", userId));
        } else {
            datas.add(new NameValuePair("auid", sharedPrefManager.getAuid()));
        }

        return createAsyncOperation("fetchCityNewsDetail", resultReceiver, taskMark, tracker, datas);
    }

    /**
     * 用户评论
     *
     * @param resultReceiver     结果接收器
     * @param taskMark           任务标记
     * @param userId             用户id
     * @param postId             文章id
     * @param userCommentContent 评论内容
     * @param commentParentId    父评论id
     * @return
     */
    public AsyncOperation userInsertComment(IResultReceiver resultReceiver, ATaskMark taskMark, String userId,
                                            String postId, String userCommentContent, String commentParentId) {
        UserInsertCommentTracker tracker = new UserInsertCommentTracker(modulel, resultReceiver);
        List<NameValuePair> datas = new ArrayList<>();
        datas.add(new NameValuePair("page", "user_insert_comment"));
        datas.add(new NameValuePair("post_id", postId));
        datas.add(new NameValuePair("user_id", userId));
        datas.add(new NameValuePair("user_comment_content", userCommentContent));
        if (!StringUtil.isEmptyString(commentParentId)) {
            datas.add(new NameValuePair("comment_parent_id", commentParentId));
        }

        return createAsyncOperation("userInsertComment", resultReceiver, taskMark, tracker, datas);
    }

    /**
     * 搜索接口
     *
     * @param resultReceiver
     * @param taskMark
     * @param from
     * @param size
     * @return
     */
    public AsyncOperation userSearch(IResultReceiver resultReceiver, ATaskMark taskMark, String keyWord,
                                     String fromType, String from, String size, String complete) {

        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);
                return operation;
            } else {
                UserSearchTracker tracker = new UserSearchTracker(modulel, resultReceiver);
                operation = wraperOperation(tracker, taskMark, "userSearch", null);
                operation.excuteOperate(service, keyWord, fromType, from, size, complete);
            }

        } catch (Exception e) {
        }
        return null;
    }

    /**
     * 查询评论列表
     *
     * @param resultReceiver 结果接收器
     * @param postId         文章id
     * @param userId         用户id
     * @return
     */
    public AsyncOperation fetchComments(IResultReceiver resultReceiver, String postId, String userId) {
        FetchCommentsTaskMark taskMark = taskMarkPool.getFetchCommentsTaskMark(postId);
        FetchCommentsTracker tracker = new FetchCommentsTracker(modulel, resultReceiver);
        PageInfo pageInfo = taskMark.getPageInfo();
        List<NameValuePair> datas = new ArrayList<>();
        datas.add(new NameValuePair("page", "post_comments"));
        datas.add(new NameValuePair("post_id", postId));
        datas.add(new NameValuePair("from", pageInfo.getNextFrom()+""));
        datas.add(new NameValuePair("size", pageInfo.getSize()+""));
        if (!StringUtil.isEmptyString(userId)) {
            datas.add(new NameValuePair("user_id", userId));
        } else {
            datas.add(new NameValuePair("auid", sharedPrefManager.getAuid()));
        }

        return createAsyncOperation("fetchComments", resultReceiver, taskMark, tracker, datas);
    }

    /**
     * 搜索结果
     *
     * @param resultReceiver
     * @param keyWord
     * @param postType
     * @return
     */
    public AsyncOperation userSearchResult(IResultReceiver resultReceiver, SearchResultTaskMark taskMark, String
            keyWord, String postType) {
        UserSearchTotalTracker tracker = new UserSearchTotalTracker(modulel, resultReceiver);
        PageInfo pageInfo = taskMark.getPageInfo();
        List<NameValuePair> datas = new ArrayList<>();
        datas.add(new NameValuePair("page", "user_search"));
        datas.add(new NameValuePair("keyword_string", keyWord));
        datas.add(new NameValuePair("post_type", postType));
        datas.add(new NameValuePair("from", pageInfo.getNextFrom()+""));
        datas.add(new NameValuePair("size", pageInfo.getSize()+""));

        return createAsyncOperation("userSearchTotal", resultReceiver, taskMark, tracker, datas);
    }

    /**
     * 保存分享图片
     *
     * @param resultReceiver
     * @param taskMark
     * @param imgUrl
     * @param dir
     * @return
     */
    public AsyncOperation saveShareImg(IResultReceiver resultReceiver, ATaskMark taskMark, String imgUrl, String dir) {
        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);
                return operation;
            } else {
                EmptyTracker tracker = new EmptyTracker(modulel, resultReceiver);
                operation = wraperOperation(tracker, taskMark, "saveShareImg", null);
                operation.excuteOperate(service, imgUrl, dir);
            }

        } catch (Exception e) {
        }
        return null;
    }

    /**
     * 举报
     *
     * @param resultReceiver 结果接收器
     * @param taskMark       任务标记
     * @param userId         用户id
     * @param targetId       目标项id
     * @param targetType     举报类型
     * @param content        举报内容
     * @return
     */
    public AsyncOperation commentReport(IResultReceiver resultReceiver, ATaskMark taskMark, String userId,
                                        String targetId, String targetType, String content) {
        EmptyTracker tracker = new EmptyTracker(modulel, resultReceiver);
        List<NameValuePair> datas = new ArrayList<>();
        datas.add(new NameValuePair("page", "user_post_report"));
        datas.add(new NameValuePair("report_target_id", targetId));
        datas.add(new NameValuePair("report_target_type", targetType));
        datas.add(new NameValuePair("report_content", content));
        datas.add(new NameValuePair("user_id", userId));

        return createAsyncOperation("commentReport", resultReceiver, taskMark, tracker, datas);
    }

    /**
     * 首页结果
     *
     * @param resultReceiver
     * @param taskMark
     * @param from
     * @param size
     * @return
     */
    public AsyncOperation homePage(IResultReceiver resultReceiver, ATaskMark taskMark, int from, int size, String version) {

        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);
                return operation;
            } else {
                HomePageTracker tracker = new HomePageTracker(modulel, resultReceiver);
                operation = wraperOperation(tracker, taskMark, "homePage", null);
                operation.excuteOperate(service, from, size, version);
            }

        } catch (Exception e) {
        }
        return null;
    }

    /**
     * 我的关注，我的文章，我的评论 @我的评论
     *
     * @param resultReceiver
     * @param taskMark
     * @param userId
     * @param from
     * @param size
     * @param postType
     * @param pageType
     * @return
     */
    public AsyncOperation myArticleFollowAndComments(IResultReceiver resultReceiver, ATaskMark taskMark, String userId,
                                                     String from, String size, String postType, String pageType) {
        MyArticleFollowCommentTracker tracker = new MyArticleFollowCommentTracker(modulel, resultReceiver);
        List<NameValuePair> datas = new ArrayList<>();
        datas.add(new NameValuePair("page", pageType));
        datas.add(new NameValuePair("user_id", userId));
        datas.add(new NameValuePair("from", from+""));
        datas.add(new NameValuePair("size", size+""));
        if (!StringUtil.isEmptyString(postType)) {
            datas.add(new NameValuePair("post_type", postType));
        }

        return createAsyncOperation("myArticleFollowAndComments", resultReceiver, taskMark, tracker, datas);
    }

    /**
     * 用户发布文章
     *
     * @param resultReceiver
     * @param taskMark
     * @param userId
     * @param title
     * @param content
     * @param attachmentImage
     * @param category
     * @return
     */
    public AsyncOperation userPostArticle(IResultReceiver resultReceiver, ATaskMark taskMark, String userId,
                                          String title, String content, List<String> attachmentImage, String category) {
        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);
                return operation;
            }
            EmptyTracker tracker = new EmptyTracker(modulel, resultReceiver);
            operation = wraperOperation(tracker, taskMark, "userPostArticle", null);
            operation.excuteOperate(service, userId, title, content, attachmentImage, category);
        } catch (Exception e) {
        }

        return null;
    }

    public AsyncOperation uploadUserPost(IResultReceiver resultReceiver, ATaskMark taskMark, String userId,
                                         String postId, String content, List<String> attachmentImage, String status,
                                         String category, String subcategory, String price, String city, String phone, String email) {

        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);
                return operation;
            }
            UploadUserPostTracker uploadUserPostTracker = new UploadUserPostTracker(modulel, resultReceiver);
            operation = wraperOperation(uploadUserPostTracker, taskMark, "uploadUserPost", null);
            operation.excuteOperate(service, userId, postId, content, attachmentImage, status, category, subcategory, price, city, phone, email);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }


    /**
     * 查询城惠列表
     *
     * @param resultReceiver 结果接收器
     * @param taskMark       任务标记
     * @param from           起始纪录项
     * @param size           查询记录数
     * @param userId         用户id
     * @param lat            经度
     * @param lng            维度
     * @return
     */
    public AsyncOperation fetchCityDiscounts(IResultReceiver resultReceiver, ATaskMark taskMark, int from, int size,
                                             String userId, double lat, double lng) {
        FetchCityDiscountsTracker tracker = new FetchCityDiscountsTracker(modulel, resultReceiver);
        List<NameValuePair> datas = new ArrayList<>();
        datas.add(new NameValuePair("page", "business_home"));
        if (!StringUtil.isEmptyString(userId)) {
            datas.add(new NameValuePair("user_id", userId));
        }
        datas.add(new NameValuePair("from", from+""));
        datas.add(new NameValuePair("size", size+""));
        if (lat != 0 || lng != 0) {
            datas.add(new NameValuePair("user_lat", lat+""));
            datas.add(new NameValuePair("user_lng", lng+""));
        }

        String checksum = (String) PersistentCacheManager.getInstance().getObject(PersistentCacheManager.BUSINESS_HOME_CHECKSUM_KEY);
        if (!StringUtil.isEmptyString(checksum)) {
            datas.add(new NameValuePair("checksum", checksum));
        }

        return createAsyncOperation("fetchCityDiscounts", resultReceiver, taskMark, tracker, datas);
    }


    public AsyncOperation fetchUserPosts(IResultReceiver resultReceiver, FetchUserPostsTaskMark taskMark, String userId) {
        FetchUserPostsTracker tracker = new FetchUserPostsTracker(modulel, resultReceiver);
        PageInfo pageInfo = taskMark.getPageInfo();
        List<NameValuePair> data = new ArrayList<>();
        data.add(new NameValuePair("page", "userpost_home"));
        data.add(new NameValuePair("from", pageInfo.getNextFrom() + ""));
        data.add(new NameValuePair("size", pageInfo.getSize() + ""));
        if (!StringUtil.isEmptyString(taskMark.getFilter())) {
            data.add(new NameValuePair("filter_args", taskMark.getFilter()));
        }
        if (!StringUtil.isEmptyString(userId)) {
            data.add(new NameValuePair("user_id", userId));
        }

        return createAsyncOperation("fetchUserPosts", resultReceiver, taskMark, tracker, data);
    }

    public AsyncOperation getUserPosts(IResultReceiver resultReceiver, GetUserPostsTaskMark taskMark) {

        GetUserPostsTracker tracker = new GetUserPostsTracker(modulel, resultReceiver);
        PageInfo pageInfo = taskMark.getPageInfo();
        List<NameValuePair> data = new ArrayList<>();
        data.add(new NameValuePair("page", taskMark.getPage())); // page = "userpost_history" or "userpost_following"
        data.add(new NameValuePair("from", pageInfo.getNextFrom() + ""));
        data.add(new NameValuePair("size", pageInfo.getSize() + ""));
        data.add(new NameValuePair("user_id", taskMark.getUserId()));
        if (!StringUtil.isEmptyString(taskMark.getStatus())) {
            data.add(new NameValuePair("post_status", taskMark.getStatus()));
        }

        return createAsyncOperation("getUserPosts", resultReceiver, taskMark, tracker, data);
    }

    public AsyncOperation fetchUserPostCategories(IResultReceiver resultReceiver, FetchUserPostCategoriesTaskMark taskMark) {
        FetchUserPostCategoriesTracker tracker = new FetchUserPostCategoriesTracker(modulel, resultReceiver);
        List<NameValuePair> data = new ArrayList<>();
        data.add(new NameValuePair("page", "userpost_categories"));

        return createAsyncOperation("fetchUserPostCategories", resultReceiver, taskMark, tracker, data);
    }

    /**
     * 根据类型查询城惠列表
     *
     * @param resultReceiver 结果接收器
     * @param taskMark       任务标记
     * @param from           起始纪录项
     * @param size           查询记录数
     * @param userId         用户id
     * @param category       类型
     * @param subcategory    子类型
     * @param city           城市
     * @param filter         过滤条件
     * @param sort           排序
     * @param lat            经度
     * @param lng            维度
     * @return
     */
    public AsyncOperation fetchCtyDiscountCategory(IResultReceiver resultReceiver, ATaskMark taskMark, int from,
                                                   int size, String userId, String category, String subcategory,
                                                   String city, String filter, String sort,
                                                   double lat, double lng) {
        FetchCityDiscountsCategoryTracker tracker = new FetchCityDiscountsCategoryTracker(modulel, resultReceiver);
        List<NameValuePair> datas = new ArrayList<>();
        datas.add(new NameValuePair("page", "business_home"));
        if (!StringUtil.isEmptyString(userId)) {
            datas.add(new NameValuePair("user_id", userId));
        }
        datas.add(new NameValuePair("from", from+""));
        datas.add(new NameValuePair("size", size+""));
        datas.add(new NameValuePair("category", category));
        datas.add(new NameValuePair("subcategory", subcategory));
        if (!StringUtil.isEmptyString(city)) {
            datas.add(new NameValuePair("city", city));
        }
        if (!StringUtil.isEmptyString(filter)) {
            datas.add(new NameValuePair("other_filter", filter));
        }
        if (!StringUtil.isEmptyString(sort)) {
            datas.add(new NameValuePair("order", sort));
        }
        if (lat != 0 || lng != 0) {
            datas.add(new NameValuePair("user_lat", lat+""));
            datas.add(new NameValuePair("user_lng", lng+""));
        }

        return createAsyncOperation("fetchCtyDiscountCategory", resultReceiver, taskMark, tracker, datas);
    }

    public AsyncOperation myUserNotice(IResultReceiver resultReceiver, ATaskMark taskMark, String pageType) {
        MyUserNoticeTracker tracker = new MyUserNoticeTracker(modulel, resultReceiver);
        List<NameValuePair> datas = new ArrayList<>();
        datas.add(new NameValuePair("page", pageType));

        return createAsyncOperation("myUserNotice", resultReceiver, taskMark, tracker, datas);
    }

    /**
     * 删除用户评论
     *
     * @param resultReceiver 结果接收器
     * @param taskMark       任务标记
     * @param userId         用户id
     * @param commentId      评论id
     * @return
     */
    public AsyncOperation userDeleteComment(IResultReceiver resultReceiver, ATaskMark taskMark, String userId,
                                            String commentId) {
        UserDelCommentTracker tracker = new UserDelCommentTracker(modulel, resultReceiver);
        List<NameValuePair> datas = new ArrayList<>();
        datas.add(new NameValuePair("page", "user_delete_comment"));
        datas.add(new NameValuePair("comment_id", commentId));
        datas.add(new NameValuePair("user_id", userId));

        return createAsyncOperation("userDeleteComment", resultReceiver, taskMark, tracker, datas);
    }

    /**
     * 查询城惠详情
     *
     * @param resultReceiver 结果接收器
     * @param taskMark       任务标记
     * @param postId         城惠id
     * @param userId         用户id
     * @return
     */
    public AsyncOperation fetchDiscountDetail(IResultReceiver resultReceiver, ATaskMark taskMark, String postId,
                                              String userId, double lat, double lng) {
        FetchDiscountDetailTracker tracker = new FetchDiscountDetailTracker(modulel, resultReceiver);
        List<NameValuePair> datas = new ArrayList<>();
        datas.add(new NameValuePair("page", "business_single"));
        datas.add(new NameValuePair("post_id", postId));
        if (!StringUtil.isEmptyString(userId)) {
            datas.add(new NameValuePair("user_id", userId));
        } else {
            datas.add(new NameValuePair("auid", sharedPrefManager.getAuid()));
        }
        if (lat != 0 || lng != 0) {
            datas.add(new NameValuePair("user_lat", lat+""));
            datas.add(new NameValuePair("user_lng", lng+""));
        }

        return createAsyncOperation("fetchDiscountDetail", resultReceiver, taskMark, tracker, datas);
    }

    public AsyncOperation fetchUserPostDetail(IResultReceiver resultReceiver, ATaskMark taskMark, String postId,
                                              String userId, double lat, double lng) {

        FetchUserPostDetailTracker tracker = new FetchUserPostDetailTracker(modulel, resultReceiver);
        List<NameValuePair> data = new ArrayList<>();
        data.add(new NameValuePair("page", "userpost_single"));
        data.add(new NameValuePair("post_id", postId));
        if (!StringUtil.isEmptyString(userId)) {
            data.add(new NameValuePair("user_id", userId));
        } else {
            data.add(new NameValuePair("auid", sharedPrefManager.getAuid()));
        }
        if (lat != 0 || lng != 0) {
            data.add(new NameValuePair("user_lat", lat+""));
            data.add(new NameValuePair("user_lng", lng+""));
        }

        return createAsyncOperation("fetchUserPostDetail", resultReceiver, taskMark, tracker, data);
    }

    /**
     * 图片更新
     *
     * @param resultReceiver
     * @param taskMark
     * @param userId
     * @param imageUrl
     * @return
     */
    public AsyncOperation userUploadImage(IResultReceiver resultReceiver, ATaskMark taskMark, String userId,
                                          String imageUrl) {
        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);
                return operation;
            }
            ChangeUserImagerTracker tracker = new ChangeUserImagerTracker(modulel, resultReceiver);
            operation = wraperOperation(tracker, taskMark, "userUploadImage", null);
            operation.excuteOperate(service, userId, imageUrl);
        } catch (Exception e) {
        }

        return null;
    }

    /**
     * 用户评论星级
     *
     * @param resultReceiver 结果接收器
     * @param taskMark       任务标记
     * @param postId         文章id
     * @param userId         用户id
     * @param rating         星级
     * @return
     */
    public AsyncOperation userRateBusiness(IResultReceiver resultReceiver, ATaskMark taskMark, String postId,
                                           String userId, float rating) {
        UserRateTracker tracker = new UserRateTracker(modulel, resultReceiver);
        List<NameValuePair> datas = new ArrayList<>();
        datas.add(new NameValuePair("page", "user_rate_business"));
        datas.add(new NameValuePair("post_id", postId));
        datas.add(new NameValuePair("user_id", userId));
        datas.add(new NameValuePair("rating", rating+""));

        return createAsyncOperation("userRateBusiness", resultReceiver, taskMark, tracker, datas);
    }

    /**
     * 添加用户的token
     *
     * @param resultReceiver 结果接收器
     * @param taskMark       任务标记
     * @param userId         用户id
     * @param registrationId gcm注册id
     * @param status         状态
     * @param auid           auid
     * @return
     */
    public AsyncOperation addUserToken(IResultReceiver resultReceiver, ATaskMark taskMark, String userId,
                                       String registrationId, String status, String auid) {
        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);
                return operation;
            }
            AddUserTokenTracker tracker = new AddUserTokenTracker(modulel, resultReceiver);
            operation = wraperOperation(tracker, taskMark, "addUserToken", null);
            operation.excuteOperate(service, userId, registrationId, status, auid);
        } catch (Exception e) {
        }

        return null;
    }

    public AsyncOperation addUserToken(IResultReceiver resultReceiver, ATaskMark taskMark, String userId,
                                       String fcmToken) {
        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);
                return operation;
            }
            AddUserTokenTracker tracker = new AddUserTokenTracker(modulel, resultReceiver);
            operation = wraperOperation(tracker, taskMark, "addUserToken", null);
            operation.excuteOperate(service, userId, fcmToken);
        } catch (Exception e) {
        }

        return null;
    }

    /**
     * 删除文章
     *
     * @param resultReceiver 结果接收器
     * @param taskMark       任务标记
     * @param postId         文章id
     * @param userId         用户id
     * @return
     */
    public AsyncOperation userDeleteArticle(IResultReceiver resultReceiver, ATaskMark taskMark, String postId,
                                            String userId) {
        UserDeleteArticleTracker tracker = new UserDeleteArticleTracker(modulel, resultReceiver);
        List<NameValuePair> datas = new ArrayList<>();
        datas.add(new NameValuePair("page", "user_delete_article"));
        datas.add(new NameValuePair("post_id", postId));
        datas.add(new NameValuePair("user_id", userId));

        return createAsyncOperation("userDeleteArticle", resultReceiver, taskMark, tracker, datas);
    }

    /**
     * 上传推送设置
     *
     * @param resultReceiver   结果接收器
     * @param taskMark         任务标记
     * @param userId           用户id
     * @param postReminder     文章评论推送
     * @param commentReminder  at我的评论推送
     * @param businessReminder 关注商家推送
     * @return
     */
    public AsyncOperation setMessageRemind(IResultReceiver resultReceiver, ATaskMark taskMark, String userId,
                                           boolean postReminder, boolean commentReminder, boolean businessReminder) {
        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);
                return operation;
            }
            EmptyTracker tracker = new EmptyTracker(modulel, resultReceiver);
            operation = wraperOperation(tracker, taskMark, "setMessageRemind", null);
            operation.excuteOperate(service, userId, postReminder, commentReminder, businessReminder);
        } catch (Exception e) {
        }

        return null;
    }

    /**
     * 获取用户推送设置
     *
     * @param resultReceiver 结果接收器
     * @param taskMark       任务标记
     * @param userId         用户id
     * @return
     */
    public AsyncOperation userGetNoticationSetting(IResultReceiver resultReceiver, ATaskMark taskMark, String userId) {
        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);
                return operation;
            }
            UserGetNoticationSettingTracker tracker = new UserGetNoticationSettingTracker(modulel, resultReceiver);
            operation = wraperOperation(tracker, taskMark, "userGetNotificationSetting", null);
            operation.excuteOperate(service, userId);
        } catch (Exception e) {
        }

        return null;
    }

    /**
     * 获取auid
     *
     * @param resultReceiver 结果接收器
     * @param taskMark       任务标记
     * @param androidId
     * @param imei
     * @return
     */
    public AsyncOperation userGetAuid(IResultReceiver resultReceiver, ATaskMark taskMark, String androidId, String
            imei) {
        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);
                return operation;
            }
            UserGetAuidTracker tracker = new UserGetAuidTracker(modulel, resultReceiver);
            operation = wraperOperation(tracker, taskMark, "userGetAuid", null);
            operation.excuteOperate(service, androidId, imei);
        } catch (Exception e) {
        }

        return null;
    }

    /**
     * 版本更新
     *
     * @param resultReceiver
     * @param taskMark
     * @return
     */
    public AsyncOperation updateVersion(IResultReceiver resultReceiver, ATaskMark taskMark) {
        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);
                return operation;
            }
            VersionInfoTracker tracker = new VersionInfoTracker(modulel, resultReceiver);
            operation = wraperOperation(tracker, taskMark, "updateVersion", null);
            operation.excuteOperate(service);
        } catch (Exception e) {
        }

        return null;
    }

    /**
     * 版本更新
     *
     * @param resultReceiver
     * @param taskMark
     * @return
     */
    public AsyncOperation sendSplashAd(IResultReceiver resultReceiver, ATaskMark taskMark) {
        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);
                return operation;
            }
            SplashAdInfoTracker tracker = new SplashAdInfoTracker(modulel, resultReceiver);
            operation = wraperOperation(tracker, taskMark, "sendSplashAd", null);
            operation.excuteOperate(service);
        } catch (Exception e) {
        }

        return null;
    }

    /**
     * 城惠地图页查询商家
     *
     * @param resultReceiver 结果接收器
     * @param taskMark       任务标记
     * @param userId         用户id
     * @param lat 纬度
     * @param lng 经度
     * @param top
     * @param down
     * @param left
     * @param right
     * @param mapFilter 过滤条件
     * @return
     */
    public AsyncOperation homeMap(IResultReceiver resultReceiver, ATaskMark taskMark,String userId,double lat,double lng,double top,double down,double left,double right,String mapFilter) {
        FetchHomeMapTracker tracker = new FetchHomeMapTracker(modulel, resultReceiver);
        List<NameValuePair> datas = new ArrayList<>();
        datas.add(new NameValuePair("page", "business_home_map"));
        if (!StringUtil.isEmptyString(userId)) {
            datas.add(new NameValuePair("user_id", userId));
        }
        if (lat!=0 && lng!=0) {
            datas.add(new NameValuePair("user_lat", lat+""));
            datas.add(new NameValuePair("user_lng", lng+""));
        }
        datas.add(new NameValuePair("top", top+""));
        datas.add(new NameValuePair("down", down+""));
        datas.add(new NameValuePair("left", left+""));
        datas.add(new NameValuePair("right", right+""));
        datas.add(new NameValuePair("map_filter", mapFilter));

        return createAsyncOperation("homeMap", resultReceiver, taskMark, tracker, datas);
    }

    public AsyncOperation liveFeed(IResultReceiver resultReceiver, ATaskMark taskMark, String from, String size ,String pageType) {
        LiveFeedTracker tracker = new LiveFeedTracker(modulel, resultReceiver);
        List<NameValuePair> datas = new ArrayList<>();
        datas.add(new NameValuePair("page", pageType));
        datas.add(new NameValuePair("from", from));
        datas.add(new NameValuePair("size", size));

        return createAsyncOperation("liveFeed", resultReceiver, taskMark, tracker, datas);
    }

    public AsyncOperation editUserProfile(IResultReceiver resultReceiver, ATaskMark taskMark, String userId, String displayName, String email, String phone, String city) {

        UserEditProfileTracker userEditProfileTracker = new UserEditProfileTracker(modulel, resultReceiver);
        List<NameValuePair> data = new ArrayList<>();
        data.add(new NameValuePair("page", "user_edit_profile"));
        data.add(new NameValuePair("user_id", userId));
        data.add(new NameValuePair("display_name", displayName));
        if (!StringUtil.isEmptyString(email)) {
            data.add(new NameValuePair("user_email", email));
        }
        if (!StringUtil.isEmptyString(phone)) {
            data.add(new NameValuePair("user_phone", phone));
        }
        if (!StringUtil.isEmptyString(city)) {
            data.add(new NameValuePair("user_city", city));
        }
        return createAsyncOperation("editUserProfile", resultReceiver, taskMark, userEditProfileTracker, data);
    }

    public AsyncOperation resetPassword(IResultReceiver resultReceiver, ATaskMark taskMark, String userId, String oldPassword, String newPassword) {

        EmptyTracker emptyTracker = new EmptyTracker(modulel, resultReceiver);
        List<NameValuePair> data = new ArrayList<>();
        data.add(new NameValuePair("page", "user_reset_password"));
        data.add(new NameValuePair("user_id", userId));
        data.add(new NameValuePair("old_password", oldPassword));
        data.add(new NameValuePair("new_password", newPassword));

        return createAsyncOperation("resetPassword", resultReceiver, taskMark, emptyTracker, data);
    }

    public AsyncOperation setListingsPrivacy(IResultReceiver resultReceiver, ATaskMark taskMark, String userId, String watchListPrivacy) {

        PostPrivacySettingTracker postPrivacySettingTracker = new PostPrivacySettingTracker(modulel, resultReceiver);
        List<NameValuePair> data = new ArrayList<>();
        data.add(new NameValuePair("page", "user_privacy_setting"));
        data.add(new NameValuePair("user_id", userId));
        data.add(new NameValuePair("watch_list_public", watchListPrivacy));

        return createAsyncOperation("setListingsPrivacy", resultReceiver, taskMark, postPrivacySettingTracker, data);
    }

    public AsyncOperation renewUserPost(IResultReceiver resultReceiver, ATaskMark taskMark, String postId, String userId) {

        EmptyTracker emptyTracker = new EmptyTracker(modulel, resultReceiver);
        List<NameValuePair> data = new ArrayList<>();
        data.add(new NameValuePair("page", "userpost_renew"));
        data.add(new NameValuePair("post_id", postId));
        data.add(new NameValuePair("user_id", userId));

        return createAsyncOperation("renewUserPost", resultReceiver, taskMark, emptyTracker, data);
    }

    public AsyncOperation fetchMyUserPostComments(IResultReceiver resultReceiver, ATaskMark taskMark, String userId, String from, String size) {

        MyArticleFollowCommentTracker tracker = new MyArticleFollowCommentTracker(modulel, resultReceiver);
        List<NameValuePair> data = new ArrayList<>();
        data.add(new NameValuePair("page", "comments_to_my_userposts"));
        data.add(new NameValuePair("user_id", userId));
        data.add(new NameValuePair("from", from+""));
        data.add(new NameValuePair("size", size+""));

        return createAsyncOperation("fetchMyUserPostComments", resultReceiver, taskMark, tracker, data);
    }

    public AsyncOperation uploadBusinessPhotos(IResultReceiver resultReceiver, ATaskMark taskMark, String userId, String postId, List<String> images, String caption) {

        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);
                return operation;
            }
            EmptyTracker emptyTracker = new EmptyTracker(modulel, resultReceiver);
            operation = wraperOperation(emptyTracker, taskMark, "uploadBusinessPhotos", null);
            operation.excuteOperate(service, userId, postId, images, caption);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }

    public AsyncOperation fetchUserBusinessImages(IResultReceiver resultReceiver, ATaskMark taskMark, String userId) {

        FetchUserBusinessImagesTracker tracker = new FetchUserBusinessImagesTracker(modulel, resultReceiver);
        FetchUserBusinessImagesTaskMark fetchUserBusinessImagesTaskMark = (FetchUserBusinessImagesTaskMark) taskMark;
        PageInfo pageInfo = fetchUserBusinessImagesTaskMark.getPageInfo();
        List<NameValuePair> data = new ArrayList<>();
        data.add(new NameValuePair("page", "user_posted_business_images"));
        data.add(new NameValuePair("user_id", userId));
        data.add(new NameValuePair("from", pageInfo.getNextFrom() + ""));
        data.add(new NameValuePair("size", pageInfo.getSize() + ""));

        return createAsyncOperation("fetchUserBusinessImages", resultReceiver, taskMark, tracker, data);
    }

    public AsyncOperation deleteUserBusinessImages(IResultReceiver resultReceiver, ATaskMark taskMark, String userId, Set<String> imgUrls) {

        EmptyTracker tracker = new EmptyTracker(modulel, resultReceiver);
        List<NameValuePair> data = new ArrayList<>();
        data.add(new NameValuePair("page", "delete_business_image"));
        data.add(new NameValuePair("user_id", userId));
        data.add(new NameValuePair("images_array", JSON.toJSONString(imgUrls)));

        return createAsyncOperation("deleteUserBusinessImages", resultReceiver, taskMark, tracker, data);
    }

    /**
     * 获取用户 hash code
     * @param resultReceiver
     * @param taskMark
     * @param userId
     * @param auid
     * @return
     */
    public AsyncOperation userHash(IResultReceiver resultReceiver, ATaskMark taskMark, String userId, String auid) {
        try {
            AsyncOperation operation = null;
            if (AsyncOperation.isTaskExist(taskMark)) {
                operation = takeoverExistTask(resultReceiver, taskMark);

            } else {
                UserHashTracker tracker = new UserHashTracker(modulel, resultReceiver);
                operation = wraperOperation(tracker, taskMark, "userHash", null);
                operation.excuteOperate(service, userId, auid);

            }

            return operation;
        } catch (Exception e) {
        }

        return null;
    }
}